package cn.sc.summer.constant.util;

import cn.hutool.core.lang.tree.TreeNodeConfig;

/**
 * 类名：树结构工具类
 *
 * @author a-xin
 * @date 2024/8/6 15:35
 */
public class TreeUtilX {

    /**
     * 树结构默认子类字段
     */
    private static final String CHILDREN_KEY = "child";

    /**
     * 树结构默认ID字段
     */
    private static final String ID_KEY = "id";

    /**
     * 树结构默认父级ID字段
     */
    private static final String PARENT_KEY = "pId";

    /**
     * 获取默认树结构配置项
     *
     * @param deep 树结构层级
     * @return 树结构配置
     */
    public static TreeNodeConfig getStrConfig(Integer deep) {
        TreeNodeConfig treeNodeConfig = new TreeNodeConfig();
        treeNodeConfig.setDeep(deep);
        treeNodeConfig.setChildrenKey(CHILDREN_KEY);
        treeNodeConfig.setIdKey(ID_KEY);
        treeNodeConfig.setParentIdKey(PARENT_KEY);
        return treeNodeConfig;
    }

    /**
     * 获取默认树结构配置项
     *
     * @param deep        树结构层级
     * @param childKey    子集字段
     * @param idKey       id字段
     * @param parentIdKey 父级ID字段
     * @return 树结构配置
     */
    public static TreeNodeConfig getStrConfig(Integer deep, String childKey, String idKey, String parentIdKey) {
        TreeNodeConfig treeNodeConfig = new TreeNodeConfig();
        treeNodeConfig.setDeep(deep);
        treeNodeConfig.setChildrenKey(childKey);
        treeNodeConfig.setIdKey(idKey);
        treeNodeConfig.setParentIdKey(parentIdKey);
        return treeNodeConfig;
    }

}
